import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p002 from './p002';

interface Par extends Event {
	page_no: number;
}
export default async function a007(fd: IFeidaoAiBrowserComponent, e: Par) {
	set(fd, 'pn', e.page_no);
	let equip_depart = get(fd, 'equip_depart');
	if (equip_depart === undefined) {
		equip_depart = "";
	}
	let project = get(fd, 'project');
	if (project === undefined) {
		project = "";
	}
	let assetsname = get(fd, 'assetsname');
	if (assetsname === undefined) {
		assetsname = "";
	}
	let asset_classification = get(fd, 'asset_classification');
	if (asset_classification === undefined) {
		asset_classification = "";
	}
	let timeout_alert = get(fd, 'timeout_alert');
	if (timeout_alert === undefined) {
		timeout_alert = "";
	}
	let customer_assets = get(fd, 'customer_assets');
	if (customer_assets === undefined) {
		customer_assets = "";
	}// 获取储存的值
	const type = get(fd, 'type');
	let name = get(fd, 'name');
	if (name === undefined) {
		name = "maintenance_time";
	}
	const data = {
		responsible_no: "YG00000077",
		equip_depart,
		project,
		assetsname,
		asset_classification,
		timeout_alert,
		customer_assets,
		type,
		name,
		pn: e.page_no
	};
	// 获取搜索的数据
	if (type === "0" || type === undefined) {
		// 获取排序后的数据
		const res = await nodejs<{ dt: Array<{}>; coun: number }>(
			'project-assets/zj-000002/s001', {
				filter: data
			});
		if (res.dt.length > 0) {
			render(fd, res.dt, p001, 'p001', 'inner');
		} else {
			render(fd, "", p002, 'p002', 'inner');
		}
	} else {
		// 获取排序后的数据
		const res = await nodejs<{ dt: Array<{}>; coun: number }>(
			'project-assets/zj-000002/s001', {
				filter: data
			});
		if (res.dt.length > 0) {
			render(fd, res.dt, p001, 'p001', 'inner');
		} else {
			render(fd, "", p002, 'p002', 'inner');
		}
	}
}
